try:
    import Tkinter as tk  # Python 2
except ImportError:
    import tkinter as tk  # Python 3
try:
    import tkFont
except ImportError:
    import tkinter.font as tkFont
try:
    import ttk
except ImportError:
    import tkinter.ttk as ttk

import httplib2
from bs4 import BeautifulSoup
import youtube_dl


class TubeLogger(object):
    def debug(self, msg):
        print('DEBUG: ' + msg)

    def warning(self, msg):
        print('WARNING: ' + msg)

    def error(self, msg):
        print('ERROR: ' + msg)


class TubeApp(tk.Tk):
    LIST_URL = "http://www.youtube.com/playlist?list="
    # LIST_ID = "PL6gx4Cwl9DGAjkwJocj7vlc_mFU-4wXJq"
    LIST_ID = "PL2D1942A4688E9D63"
    TUBE_URL = 'http://www.youtube.com/watch?v='

    def __init__(self, *args, **kwargs):
        tk.Tk.__init__(self, *args, **kwargs)
        # fonts for all widgets
        self.option_add("*Font", '"굴림" 9')
        # font to use for label widgets
        self.option_add("*Label.Font", '"굴림" 11')
        # font to use for button widgets
        self.option_add("*Button.Font", '"굴림" 8')
        # font to use for entry widgets
        self.option_add("*Entry.Font", '"굴림" 8')

        self.top_frame1 = tk.Frame(self)
        self.top_frame1.pack(side=tk.TOP, fill=tk.X, expand=False)
        self.label1 = ttk.Label(self.top_frame1, text="List ID:", anchor="e")
        self.label1.pack(side=tk.LEFT, expand=False)

        self._listurl = tk.StringVar()
        self.entry1 = ttk.Entry(self.top_frame1, textvariable=self._listurl)
        self.entry1.pack(side=tk.LEFT, fill=tk.X, expand=True)
        self._listurl.set(self.LIST_ID)
        self.get_list_button = ttk.Button(self.top_frame1, text="Get List",
                                          style="Toolbutton", command=self._on_get_list)
        self.get_list_button.pack(side=tk.RIGHT, expand=False)

        self.top_frame2 = tk.Frame(self)
        self.top_frame2.pack(side=tk.TOP, fill=tk.X, expand=False)
        self.label2 = ttk.Label(self.top_frame2, text="Tube ID:", anchor="e")
        self.label2.pack(side=tk.LEFT, expand=False)

        self._infourl = tk.StringVar()
        self.entry2 = ttk.Entry(self.top_frame2, textvariable=self._infourl)
        self.entry2.pack(side=tk.LEFT, fill=tk.X, expand=True)

        self.down_button = ttk.Button(self.top_frame2, text="Down",
                                      style="Toolbutton", command=self._on_down)
        self.down_button.pack(side=tk.RIGHT, expand=False)

        self.get_info_button = ttk.Button(self.top_frame2, text="Get Info",
                                 style="Toolbutton", command=self._on_get_info)
        self.get_info_button.pack(side=tk.RIGHT, expand=False)

        self.paned_win = tk.PanedWindow(borderwidth=0, width=1, orient=tk.HORIZONTAL)
        self.paned_win.pack(fill=tk.BOTH, expand=True)

        self.play_list = tk.Listbox(self.paned_win, width=40, selectmode=tk.EXTENDED)
        self.play_list.bind("<Double-Button-1>", self._on_double_click_play_list)
        self.play_list.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
        self.paned_win.add(self.play_list)

        #self.info_frame = tk.Frame(self.paned_win)
        #self.info_frame.pack(side=tk.RIGHT, fill=tk.BOTH, expand=True)

        self.info_list = tk.Listbox(self.paned_win, selectmode=tk.SINGLE)
        self.info_list.bind("<Double-Button-1>", self._on_double_click_play_list)
        self.info_list.pack(side=tk.RIGHT, fill=tk.BOTH, expand=True)

        self.paned_win.add(self.info_list)


        self.entry1.bind("<Return>", self._on_get_list)
        self.entry2.bind("<Return>", self._on_get_info)

    def _on_get_list(self, event=None):
        self.play_list.delete(0, tk.END)  # clear
        h = httplib2.Http(".cache")
        resp, content = h.request(self.LIST_URL + self.LIST_ID, "GET")
        soup = BeautifulSoup(content)
        for link in soup.find_all('tr'):
            vid_id = link.get('data-video-id')
            self.play_list.insert(tk.END, vid_id)

    def progress(self, d):
        if d['status'] == 'finished':
            print('Done downloading, now converting ...')

    def _on_get_info(self, event=None):
        ydl_opts = {
            # 'format': 'bestaudio/best',
            'format': '136/137/mp4/bestvideo,140/m4a/bestaudio',
            # 'postprocessors': [{
            #     'key': 'FFmpegExtractAudio',
            #     'preferredcodec': 'mp3',
            #     'preferredquality': '192',
            # }],
            'logger': TubeLogger(),
            'progress_hooks': [self.progress],
        }
        '''
        aa = {'format_note': 'DASH audio',
'formats': [
    {'format_note': 'DASH audio', 'url': 'https://r2---sn-3u-bh2k.googlevideo.com/videoplayback?lmt=1415692982511520&requiressl=yes&clen=4933240&sparams=clen%2Cdur%2Cgir%2Cid%2Cinitcwndbps%2Cip%2Cipbits%2Citag%2Ckeepalive%2Clmt%2Cmime%2Cmm%2Cms%2Cmv%2Cpl%2Crequiressl%2Csource%2Cupn%2Cexpire&initcwndbps=2827500&key=yt5&expire=1421429745&signature=1665BBEB38AAC902FDED5DB3849035C6D10C5DF2.865308A11BF8FECE5A1C70BDF518563AA43817D0&sver=3&fexp=900718%2C905653%2C907263%2C916644%2C927622%2C931366%2C940000%2C9405888%2C941004%2C943917%2C947209%2C947225%2C948124%2C948813%2C952302%2C952605%2C952901%2C955301%2C957103%2C957105%2C957201%2C959701&ipbits=0&itag=171&upn=AaiD5abqB5I&keepalive=yes&dur=437.735&mime=audio%2Fwebm&pl=17&mv=m&mt=1421408115&ms=au&id=o-AAIeqH7Ntb6VHo7-pkn8gjKUYEiqv7nPPKT2r7rUlahn&mm=31&source=youtube&gir=yes&ip=222.112.46.51&ratebypass=yes',
     'format_id': 'nondash-171', 'vcodec': 'none', 'preference': -10050, 'abr': 128, 'player_url': None, 'ext': 'webm', 'format': 'nondash-171 - audio only (DASH audio)'},
    {'format_note': 'DASH audio', 'url': 'https://r2---sn-3u-bh2k.googlevideo.com/videoplayback?lmt=1416693191330273&requiressl=yes&clen=7028854&sparams=clen%2Cdur%2Cgir%2Cid%2Cinitcwndbps%2Cip%2Cipbits%2Citag%2Ckeepalive%2Clmt%2Cmime%2Cmm%2Cms%2Cmv%2Cpl%2Crequiressl%2Csource%2Cupn%2Cexpire&initcwndbps=2827500&key=yt5&expire=1421429745&signature=4CD7DF6B87C0C4BBF1E6E7B2CF9473D6F74B624B.4D0D5A3DD36BC6750A49204816FDEE825058D649&sver=3&fexp=900718%2C905653%2C907263%2C916644%2C927622%2C931366%2C940000%2C9405888%2C941004%2C943917%2C947209%2C947225%2C948124%2C948813%2C952302%2C952605%2C952901%2C955301%2C957103%2C957105%2C957201%2C959701&ipbits=0&itag=140&upn=AaiD5abqB5I&keepalive=yes&dur=437.788&mime=audio%2Fmp4&pl=17&mv=m&mt=1421408115&ms=au&id=o-AAIeqH7Ntb6VHo7-pkn8gjKUYEiqv7nPPKT2r7rUlahn&mm=31&source=youtube&gir=yes&ip=222.112.46.51&ratebypass=yes',
     'format_id': 'nondash-140', 'ext': 'm4a', 'vcodec': 'none', 'preference': -10050, 'abr': 128, 'player_url': None, 'acodec': 'aac', 'format': 'nondash-140 - audio only (DASH audio)'},
    {'format_note': 'DASH video', 'url': 'https://r2---sn-3u-bh2k.googlevideo.com/videoplayback?lmt=1416693171345704&requiressl=yes&clen=5761654&sparams=clen%2Cdur%2Cgir%2Cid%2Cinitcwndbps%2Cip%2Cipbits%2Citag%2Ckeepalive%2Clmt%2Cmime%2Cmm%2Cms%2Cmv%2Cpl%2Crequiressl%2Csource%2Cupn%2Cexpire&initcwndbps=2827500&key=yt5&expire=1421429745&signature=C08A6B02EE6137EECF3AA808C0DBC38FF561D38C.929EBDF8F9CE43DF71744D05C3DBA3E0E612BA79&sver=3&fexp=900718%2C905653%2C907263%2C916644%2C927622%2C931366%2C940000%2C9405888%2C941004%2C943917%2C947209%2C947225%2C948124%2C948813%2C952302%2C952605%2C952901%2C955301%2C957103%2C957105%2C957201%2C959701&ipbits=0&itag=160&upn=AaiD5abqB5I&keepalive=yes&dur=437.666&mime=video%2Fmp4&pl=17&mv=m&mt=1421408115&ms=au&id=o-AAIeqH7Ntb6VHo7-pkn8gjKUYEiqv7nPPKT2r7rUlahn&mm=31&source=youtube&gir=yes&ip=222.112.46.51&ratebypass=yes',
     'format_id': 'nondash-160', 'acodec': 'none', 'preference': -10040, 'player_url': None, 'ext': 'mp4', 'format': 'nondash-160 - 144p (DASH video)', 'height': 144},
    {'format_note': 'DASH video', 'url': 'https://r2---sn-3u-bh2k.googlevideo.com/videoplayback?lmt=1415692995401169&requiressl=yes&clen=3792850&sparams=clen%2Cdur%2Cgir%2Cid%2Cinitcwndbps%2Cip%2Cipbits%2Citag%2Ckeepalive%2Clmt%2Cmime%2Cmm%2Cms%2Cmv%2Cpl%2Crequiressl%2Csource%2Cupn%2Cexpire&initcwndbps=2827500&key=yt5&expire=1421429745&signature=4564F7E952A824129A27A6101071C754607224CD.0922CB576F452F1BC39292CEB870AB4746C3C754&sver=3&fexp=900718%2C905653%2C907263%2C916644%2C927622%2C931366%2C940000%2C9405888%2C941004%2C943917%2C947209%2C947225%2C948124%2C948813%2C952302%2C952605%2C952901%2C955301%2C957103%2C957105%2C957201%2C959701&ipbits=0&itag=242&upn=AaiD5abqB5I&keepalive=yes&dur=437.667&mime=video%2Fwebm&pl=17&mv=m&mt=1421408115&ms=au&id=o-AAIeqH7Ntb6VHo7-pkn8gjKUYEiqv7nPPKT2r7rUlahn&mm=31&source=youtube&gir=yes&ip=222.112.46.51&ratebypass=yes',
     'format_id': 'nondash-242', 'acodec': 'none', 'preference': -10040, 'player_url': None, 'ext': 'webm', 'format': 'nondash-242 - 240p (DASH video)', 'height': 240},
    {'format_note': 'DASH video', 'url': 'https://r2---sn-3u-bh2k.googlevideo.com/videoplayback?lmt=1416693159814624&requiressl=yes&clen=13408455&sparams=clen%2Cdur%2Cgir%2Cid%2Cinitcwndbps%2Cip%2Cipbits%2Citag%2Ckeepalive%2Clmt%2Cmime%2Cmm%2Cms%2Cmv%2Cpl%2Crequiressl%2Csource%2Cupn%2Cexpire&initcwndbps=2827500&key=yt5&expire=1421429745&signature=A37D84896775278E68FE39DC991260DDB57A1B4F.126CC60F89B8907CC3E798445B4DE573F3137E3E&sver=3&fexp=900718%2C905653%2C907263%2C916644%2C927622%2C931366%2C940000%2C9405888%2C941004%2C943917%2C947209%2C947225%2C948124%2C948813%2C952302%2C952605%2C952901%2C955301%2C957103%2C957105%2C957201%2C959701&ipbits=0&itag=133&upn=AaiD5abqB5I&keepalive=yes&dur=437.666&mime=video%2Fmp4&pl=17&mv=m&mt=1421408115&ms=au&id=o-AAIeqH7Ntb6VHo7-pkn8gjKUYEiqv7nPPKT2r7rUlahn&mm=31&source=youtube&gir=yes&ip=222.112.46.51&ratebypass=yes',
     'format_id': 'nondash-133', 'acodec': 'none', 'preference': -10040, 'player_url': None, 'ext': 'mp4', 'format': 'nondash-133 - 240p (DASH video)', 'height': 240},
    {'format_note': 'DASH video', 'url': 'https://r2---sn-3u-bh2k.googlevideo.com/videoplayback?lmt=1415693009422815&requiressl=yes&clen=7824107&sparams=clen%2Cdur%2Cgir%2Cid%2Cinitcwndbps%2Cip%2Cipbits%2Citag%2Ckeepalive%2Clmt%2Cmime%2Cmm%2Cms%2Cmv%2Cpl%2Crequiressl%2Csource%2Cupn%2Cexpire&initcwndbps=2827500&key=yt5&expire=1421429745&signature=55DE3C95ECFE61DA1D9F974CCD5D1D83D405AD8F.29B3D14A3C9C11A4DDD7078F1E42C5BE9ECFDCC6&sver=3&fexp=900718%2C905653%2C907263%2C916644%2C927622%2C931366%2C940000%2C9405888%2C941004%2C943917%2C947209%2C947225%2C948124%2C948813%2C952302%2C952605%2C952901%2C955301%2C957103%2C957105%2C957201%2C959701&ipbits=0&itag=243&upn=AaiD5abqB5I&keepalive=yes&dur=437.667&mime=video%2Fwebm&pl=17&mv=m&mt=1421408115&ms=au&id=o-AAIeqH7Ntb6VHo7-pkn8gjKUYEiqv7nPPKT2r7rUlahn&mm=31&source=youtube&gir=yes&ip=222.112.46.51&ratebypass=yes',
     'format_id': 'nondash-243', 'acodec': 'none', 'preference': -10040, 'player_url': None, 'ext': 'webm', 'format': 'nondash-243 - 360p (DASH video)', 'height': 360},
    {'format_note': 'DASH video', 'url': 'https://r2---sn-3u-bh2k.googlevideo.com/videoplayback?lmt=1416693160217984&requiressl=yes&clen=10097455&sparams=clen%2Cdur%2Cgir%2Cid%2Cinitcwndbps%2Cip%2Cipbits%2Citag%2Ckeepalive%2Clmt%2Cmime%2Cmm%2Cms%2Cmv%2Cpl%2Crequiressl%2Csource%2Cupn%2Cexpire&initcwndbps=2827500&key=yt5&expire=1421429745&signature=81843D7D0D02BFC63766BBE0DAB74E7C0E0400D1.48FD9AC96485E03FFBF5FC552FA94E944959B5EB&sver=3&fexp=900718%2C905653%2C907263%2C916644%2C927622%2C931366%2C940000%2C9405888%2C941004%2C943917%2C947209%2C947225%2C948124%2C948813%2C952302%2C952605%2C952901%2C955301%2C957103%2C957105%2C957201%2C959701&ipbits=0&itag=134&upn=AaiD5abqB5I&keepalive=yes&dur=437.666&mime=video%2Fmp4&pl=17&mv=m&mt=1421408115&ms=au&id=o-AAIeqH7Ntb6VHo7-pkn8gjKUYEiqv7nPPKT2r7rUlahn&mm=31&source=youtube&gir=yes&ip=222.112.46.51&ratebypass=yes',
     'format_id': 'nondash-134', 'acodec': 'none', 'preference': -10040, 'player_url': None, 'ext': 'mp4', 'format': 'nondash-134 - 360p (DASH video)', 'height': 360},
    {'format_note': 'DASH video', 'url': 'https://r2---sn-3u-bh2k.googlevideo.com/videoplayback?lmt=1415693046776509&requiressl=yes&clen=14372481&sparams=clen%2Cdur%2Cgir%2Cid%2Cinitcwndbps%2Cip%2Cipbits%2Citag%2Ckeepalive%2Clmt%2Cmime%2Cmm%2Cms%2Cmv%2Cpl%2Crequiressl%2Csource%2Cupn%2Cexpire&initcwndbps=2827500&key=yt5&expire=1421429745&signature=570B208B83DCDB5D2996C204FD6EB039F2CCB234.C621ACBAAC30A6F41E91722FFAB22D936FFABDB8&sver=3&fexp=900718%2C905653%2C907263%2C916644%2C927622%2C931366%2C940000%2C9405888%2C941004%2C943917%2C947209%2C947225%2C948124%2C948813%2C952302%2C952605%2C952901%2C955301%2C957103%2C957105%2C957201%2C959701&ipbits=0&itag=244&upn=AaiD5abqB5I&keepalive=yes&dur=437.667&mime=video%2Fwebm&pl=17&mv=m&mt=1421408115&ms=au&id=o-AAIeqH7Ntb6VHo7-pkn8gjKUYEiqv7nPPKT2r7rUlahn&mm=31&source=youtube&gir=yes&ip=222.112.46.51&ratebypass=yes',
     'format_id': 'nondash-244', 'acodec': 'none', 'preference': -10040, 'player_url': None, 'ext': 'webm', 'format': 'nondash-244 - 480p (DASH video)', 'height': 480},
    {'format_note': 'DASH video', 'url': 'https://r2---sn-3u-bh2k.googlevideo.com/videoplayback?lmt=1416693194565587&requiressl=yes&clen=20652601&sparams=clen%2Cdur%2Cgir%2Cid%2Cinitcwndbps%2Cip%2Cipbits%2Citag%2Ckeepalive%2Clmt%2Cmime%2Cmm%2Cms%2Cmv%2Cpl%2Crequiressl%2Csource%2Cupn%2Cexpire&initcwndbps=2827500&key=yt5&expire=1421429745&signature=3A09105EF9915692FA12719F381FFA0777E46A38.C5380AAF9BA9F513F6F1DE67C751AE4758C22CD8&sver=3&fexp=900718%2C905653%2C907263%2C916644%2C927622%2C931366%2C940000%2C9405888%2C941004%2C943917%2C947209%2C947225%2C948124%2C948813%2C952302%2C952605%2C952901%2C955301%2C957103%2C957105%2C957201%2C959701&ipbits=0&itag=135&upn=AaiD5abqB5I&keepalive=yes&dur=437.666&mime=video%2Fmp4&pl=17&mv=m&mt=1421408115&ms=au&id=o-AAIeqH7Ntb6VHo7-pkn8gjKUYEiqv7nPPKT2r7rUlahn&mm=31&source=youtube&gir=yes&ip=222.112.46.51&ratebypass=yes',
     'format_id': 'nondash-135', 'acodec': 'none', 'preference': -10040, 'player_url': None, 'ext': 'mp4', 'format': 'nondash-135 - 480p (DASH video)', 'height': 480},
    {'format_note': 'DASH video', 'url': 'https://r2---sn-3u-bh2k.googlevideo.com/videoplayback?lmt=1415693049756519&requiressl=yes&clen=33890382&sparams=clen%2Cdur%2Cgir%2Cid%2Cinitcwndbps%2Cip%2Cipbits%2Citag%2Ckeepalive%2Clmt%2Cmime%2Cmm%2Cms%2Cmv%2Cpl%2Crequiressl%2Csource%2Cupn%2Cexpire&initcwndbps=2827500&key=yt5&expire=1421429745&signature=1AFCA6541CCB90C449549506EB353BC1A26636ED.1DA5FF91DE791E87BF08F421CF0F4E3CE6754B28&sver=3&fexp=900718%2C905653%2C907263%2C916644%2C927622%2C931366%2C940000%2C9405888%2C941004%2C943917%2C947209%2C947225%2C948124%2C948813%2C952302%2C952605%2C952901%2C955301%2C957103%2C957105%2C957201%2C959701&ipbits=0&itag=247&upn=AaiD5abqB5I&keepalive=yes&dur=437.667&mime=video%2Fwebm&pl=17&mv=m&mt=1421408115&ms=au&id=o-AAIeqH7Ntb6VHo7-pkn8gjKUYEiqv7nPPKT2r7rUlahn&mm=31&source=youtube&gir=yes&ip=222.112.46.51&ratebypass=yes',
     'format_id': 'nondash-247', 'acodec': 'none', 'preference': -10040, 'player_url': None, 'ext': 'webm', 'format': 'nondash-247 - 720p (DASH video)', 'height': 720},
    {'format_note': 'DASH video', 'url': 'https://r2---sn-3u-bh2k.googlevideo.com/videoplayback?lmt=1416693176456443&requiressl=yes&clen=45605559&sparams=clen%2Cdur%2Cgir%2Cid%2Cinitcwndbps%2Cip%2Cipbits%2Citag%2Ckeepalive%2Clmt%2Cmime%2Cmm%2Cms%2Cmv%2Cpl%2Crequiressl%2Csource%2Cupn%2Cexpire&initcwndbps=2827500&key=yt5&expire=1421429745&signature=44C221B13222407DECB50F48F75802B08E24C881.3F46EAFAF37130E1B3B58965CC0989975AED8092&sver=3&fexp=900718%2C905653%2C907263%2C916644%2C927622%2C931366%2C940000%2C9405888%2C941004%2C943917%2C947209%2C947225%2C948124%2C948813%2C952302%2C952605%2C952901%2C955301%2C957103%2C957105%2C957201%2C959701&ipbits=0&itag=136&upn=AaiD5abqB5I&keepalive=yes&dur=437.666&mime=video%2Fmp4&pl=17&mv=m&mt=1421408115&ms=au&id=o-AAIeqH7Ntb6VHo7-pkn8gjKUYEiqv7nPPKT2r7rUlahn&mm=31&source=youtube&gir=yes&ip=222.112.46.51&ratebypass=yes',
     'format_id': 'nondash-136', 'acodec': 'none', 'preference': -10040, 'player_url': None, 'ext': 'mp4', 'format': 'nondash-136 - 720p (DASH video)', 'height': 720},
    {'format_note': 'DASH audio', 'url': 'https://r2---sn-3u-bh2k.googlevideo.com/videoplayback?id=2b917e6860c861a3&itag=139&source=youtube&requiressl=yes&pl=17&mv=m&ms=au&mm=31&ratebypass=yes&mime=audio/mp4&gir=yes&clen=2642097&lmt=1416693179160996&dur=437.881&signature=43476A7E999182C50B17A327D89C41AF2BDE9FAE.24103B97B7929883701B8E39AEE5399AB6F68A2A&sver=3&mt=1421408115&upn=AaiD5abqB5I&fexp=900718,905653,907263,916644,927622,931366,940000,9405888,941004,943917,947209,947225,948124,948813,952302,952605,952901,955301,957103,957105,957201,959701&key=dg_yt0&ip=222.112.46.51&ipbits=0&expire=1421429745&sparams=ip,ipbits,expire,id,itag,source,requiressl,pl,mv,ms,mm,ratebypass,mime,gir,clen,lmt,dur',
     'format_id': '139', 'asr': 22050, 'vcodec': 'none', 'fps': None, 'width': None, 'preference': -50, 'filesize': 2642097, 'tbr': 49, 'abr': 48, 'ext': 'm4a', 'acodec': 'aac', 'format': '139 - audio only (DASH audio)', 'height': None},
    {'format_note': 'DASH audio', 'url': 'https://r2---sn-3u-bh2k.googlevideo.com/videoplayback?id=2b917e6860c861a3&itag=171&source=youtube&requiressl=yes&pl=17&mv=m&ms=au&mm=31&ratebypass=yes&mime=audio/webm&gir=yes&clen=4933240&lmt=1415692982511520&dur=437.735&signature=1E6BEBBEC31D653FF20C5E507877B87DC3257133.108B40E5373621095EA598188DA01CE0FF42A5D4&sver=3&mt=1421408115&upn=AaiD5abqB5I&fexp=900718,905653,907263,916644,927622,931366,940000,9405888,941004,943917,947209,947225,948124,948813,952302,952605,952901,955301,957103,957105,957201,959701&key=dg_yt0&ip=222.112.46.51&ipbits=0&expire=1421429745&sparams=ip,ipbits,expire,id,itag,source,requiressl,pl,mv,ms,mm,ratebypass,mime,gir,clen,lmt,dur',
     'format_id': '171', 'asr': 44100, 'vcodec': 'none', 'fps': None, 'width': None, 'preference': -50, 'filesize': 4933240, 'tbr': 96, 'abr': 128, 'ext': 'webm', 'format': '171 - audio only (DASH audio)', 'height': None},
    {'format_note': 'DASH audio', 'url': 'https://r2---sn-3u-bh2k.googlevideo.com/videoplayback?id=2b917e6860c861a3&itag=140&source=youtube&requiressl=yes&pl=17&mv=m&ms=au&mm=31&ratebypass=yes&mime=audio/mp4&gir=yes&clen=7028854&lmt=1416693191330273&dur=437.788&signature=993247ED96F548F401B69C6BC93D510629D61816.15299F6D5512337484397B492C5409CD43CED949&sver=3&mt=1421408115&upn=AaiD5abqB5I&fexp=900718,905653,907263,916644,927622,931366,940000,9405888,941004,943917,947209,947225,948124,948813,952302,952605,952901,955301,957103,957105,957201,959701&key=dg_yt0&ip=222.112.46.51&ipbits=0&expire=1421429745&sparams=ip,ipbits,expire,id,itag,source,requiressl,pl,mv,ms,mm,ratebypass,mime,gir,clen,lmt,dur',
     'format_id': '140', 'asr': 44100, 'vcodec': 'none', 'fps': None, 'width': None, 'preference': -50, 'filesize': 7028854, 'tbr': 129, 'abr': 128, 'ext': 'm4a', 'acodec': 'aac', 'format': '140 - audio only (DASH audio)', 'height': None},
    {'format_note': 'DASH audio', 'url': 'https://r2---sn-3u-bh2k.googlevideo.com/videoplayback?id=2b917e6860c861a3&itag=172&source=youtube&requiressl=yes&pl=17&mv=m&ms=au&mm=31&ratebypass=yes&mime=audio/webm&gir=yes&clen=7088430&lmt=1415692983094130&dur=437.732&signature=5A363F697E3F1CBADC9845BA3FA6E65D0FE8B4CA.81DEE9189A6E30EA33160D0B069C012B2A1A50A8&sver=3&mt=1421408115&upn=AaiD5abqB5I&fexp=900718,905653,907263,916644,927622,931366,940000,9405888,941004,943917,947209,947225,948124,948813,952302,952605,952901,955301,957103,957105,957201,959701&key=dg_yt0&ip=222.112.46.51&ipbits=0&expire=1421429745&sparams=ip,ipbits,expire,id,itag,source,requiressl,pl,mv,ms,mm,ratebypass,mime,gir,clen,lmt,dur',
     'format_id': '172', 'asr': 44100, 'vcodec': 'none', 'fps': None, 'width': None, 'preference': -50, 'filesize': 7088430, 'tbr': 137, 'abr': 256, 'ext': 'webm', 'format': '172 - audio only (DASH audio)', 'height': None},
    {'format_note': 'DASH audio', 'url': 'https://r2---sn-3u-bh2k.googlevideo.com/videoplayback?id=2b917e6860c861a3&itag=141&source=youtube&requiressl=yes&pl=17&mv=m&ms=au&mm=31&ratebypass=yes&mime=audio/mp4&gir=yes&clen=13958238&lmt=1416693190491240&dur=437.789&signature=76F30A6C4F0C9FEACADA070296FB0E957F6DD148.685D12C8BE267CC6941C6973802733F6215F9119&sver=3&mt=1421408115&upn=AaiD5abqB5I&fexp=900718,905653,907263,916644,927622,931366,940000,9405888,941004,943917,947209,947225,948124,948813,952302,952605,952901,955301,957103,957105,957201,959701&key=dg_yt0&ip=222.112.46.51&ipbits=0&expire=1421429745&sparams=ip,ipbits,expire,id,itag,source,requiressl,pl,mv,ms,mm,ratebypass,mime,gir,clen,lmt,dur',
     'format_id': '141', 'asr': 44100, 'vcodec': 'none', 'fps': None, 'width': None, 'preference': -50, 'filesize': 13958238, 'tbr': 255, 'abr': 256, 'ext': 'm4a', 'acodec': 'aac', 'format': '141 - audio only (DASH audio)', 'height': None},
    {'format_note': 'DASH video', 'url': 'https://r2---sn-3u-bh2k.googlevideo.com/videoplayback?id=2b917e6860c861a3&itag=278&source=youtube&requiressl=yes&pl=17&mv=m&ms=au&mm=31&ratebypass=yes&mime=video/webm&gir=yes&clen=3353539&lmt=1415693018708357&dur=437.667&signature=0EC24CAC5DB3B88DF38970CBFE5A10CB7EAD1FDB.6B22EEF1DD9B0A3330CBB77FA76031AB02A6037E&sver=3&mt=1421408115&upn=AaiD5abqB5I&fexp=900718,905653,907263,916644,927622,931366,940000,9405888,941004,943917,947209,947225,948124,948813,952302,952605,952901,955301,957103,957105,957201,959701&key=dg_yt0&ip=222.112.46.51&ipbits=0&expire=1421429745&sparams=ip,ipbits,expire,id,itag,source,requiressl,pl,mv,ms,mm,ratebypass,mime,gir,clen,lmt,dur',
     'format_id': '278', 'asr': None, 'vcodec': 'VP9', 'container': 'webm', 'fps': 15, 'width': 256, 'preference': -40, 'filesize': 3353539, 'tbr': 101, 'ext': 'webm', 'acodec': 'none', 'format': '278 - 256x144 (DASH video)', 'height': 144},
    {'format_note': 'DASH video', 'url': 'https://r2---sn-3u-bh2k.googlevideo.com/videoplayback?id=2b917e6860c861a3&itag=160&source=youtube&requiressl=yes&pl=17&mv=m&ms=au&mm=31&ratebypass=yes&mime=video/mp4&gir=yes&clen=5761654&lmt=1416693171345704&dur=437.666&signature=8CE410A801B2698623EBD29AA26397F24033B214.0E7E34069E5EDEBEBF3509A1B84FADD9EC15E421&sver=3&mt=1421408115&upn=AaiD5abqB5I&fexp=900718,905653,907263,916644,927622,931366,940000,9405888,941004,943917,947209,947225,948124,948813,952302,952605,952901,955301,957103,957105,957201,959701&key=dg_yt0&ip=222.112.46.51&ipbits=0&expire=1421429745&sparams=ip,ipbits,expire,id,itag,source,requiressl,pl,mv,ms,mm,ratebypass,mime,gir,clen,lmt,dur',
     'format_id': '160', 'asr': None, 'fps': 15, 'width': 256, 'preference': -40, 'filesize': 5761654, 'tbr': 112,
     'ext': 'mp4', 'format': '160 - 256x144 (DASH video)', 'height': 144, 'acodec': 'none'},
    {'format_note': 'DASH video', 'url': 'https://r2---sn-3u-bh2k.googlevideo.com/videoplayback?id=2b917e6860c861a3&itag=242&source=youtube&requiressl=yes&pl=17&mv=m&ms=au&mm=31&ratebypass=yes&mime=video/webm&gir=yes&clen=3792850&lmt=1415692995401169&dur=437.667&signature=8CED6E1272AC4EA43B79BAA31C301B1D74A576A5.1162C7D9F632C129678D765FB21E32236085AE69&sver=3&mt=1421408115&upn=AaiD5abqB5I&fexp=900718,905653,907263,916644,927622,931366,940000,9405888,941004,943917,947209,947225,948124,948813,952302,952605,952901,955301,957103,957105,957201,959701&key=dg_yt0&ip=222.112.46.51&ipbits=0&expire=1421429745&sparams=ip,ipbits,expire,id,itag,source,requiressl,pl,mv,ms,mm,ratebypass,mime,gir,clen,lmt,dur',
     'format_id': '242', 'asr': None, 'fps': 30, 'width': 426, 'preference': -40, 'filesize': 3792850, 'tbr': 135,
     'ext': 'webm', 'format': '242 - 426x240 (DASH video)', 'height': 240, 'acodec': 'none'},
    {'format_note': 'DASH video', 'url': 'https://r2---sn-3u-bh2k.googlevideo.com/videoplayback?id=2b917e6860c861a3&itag=133&source=youtube&requiressl=yes&pl=17&mv=m&ms=au&mm=31&ratebypass=yes&mime=video/mp4&gir=yes&clen=13408455&lmt=1416693159814624&dur=437.666&signature=0FAD2844DAD725FE6C2D4AB96124381796F738F4.5DD6CB82B56DF34199B4A30EF0F4E02ABC8075BB&sver=3&mt=1421408115&upn=AaiD5abqB5I&fexp=900718,905653,907263,916644,927622,931366,940000,9405888,941004,943917,947209,947225,948124,948813,952302,952605,952901,955301,957103,957105,957201,959701&key=dg_yt0&ip=222.112.46.51&ipbits=0&expire=1421429745&sparams=ip,ipbits,expire,id,itag,source,requiressl,pl,mv,ms,mm,ratebypass,mime,gir,clen,lmt,dur',
     'format_id': '133', 'asr': None, 'fps': 30, 'width': 426, 'preference': -40, 'filesize': 13408455, 'tbr': 261,
     'ext': 'mp4', 'format': '133 - 426x240 (DASH video)', 'height': 240, 'acodec': 'none'},
    {'format_note': 'DASH video', 'url': 'https://r2---sn-3u-bh2k.googlevideo.com/videoplayback?id=2b917e6860c861a3&itag=243&source=youtube&requiressl=yes&pl=17&mv=m&ms=au&mm=31&ratebypass=yes&mime=video/webm&gir=yes&clen=7824107&lmt=1415693009422815&dur=437.667&signature=146DE5768E4BE5CDBBD7F3D91F24FD41E31DDC1F.53E8C15B227455E27FC1234D9DCD9986D4A23AC8&sver=3&mt=1421408115&upn=AaiD5abqB5I&fexp=900718,905653,907263,916644,927622,931366,940000,9405888,941004,943917,947209,947225,948124,948813,952302,952605,952901,955301,957103,957105,957201,959701&key=dg_yt0&ip=222.112.46.51&ipbits=0&expire=1421429745&sparams=ip,ipbits,expire,id,itag,source,requiressl,pl,mv,ms,mm,ratebypass,mime,gir,clen,lmt,dur',
     'format_id': '243', 'asr': None, 'fps': 30, 'width': 640, 'preference': -40, 'filesize': 7824107, 'tbr': 293,
     'ext': 'webm', 'format': '243 - 640x360 (DASH video)', 'height': 360, 'acodec': 'none'},
    {'format_note': 'DASH video', 'url': 'https://r2---sn-3u-bh2k.googlevideo.com/videoplayback?id=2b917e6860c861a3&itag=134&source=youtube&requiressl=yes&pl=17&mv=m&ms=au&mm=31&ratebypass=yes&mime=video/mp4&gir=yes&clen=10097455&lmt=1416693160217984&dur=437.666&signature=597275F5D387AB30C10AAAC96E92EDD0961EAE96.92E84C5AB60D5EB2539E9DCC258F0BB3298FF7A8&sver=3&mt=1421408115&upn=AaiD5abqB5I&fexp=900718,905653,907263,916644,927622,931366,940000,9405888,941004,943917,947209,947225,948124,948813,952302,952605,952901,955301,957103,957105,957201,959701&key=dg_yt0&ip=222.112.46.51&ipbits=0&expire=1421429745&sparams=ip,ipbits,expire,id,itag,source,requiressl,pl,mv,ms,mm,ratebypass,mime,gir,clen,lmt,dur',
     'format_id': '134', 'asr': None, 'fps': 30, 'width': 640, 'preference': -40, 'filesize': 10097455, 'tbr': 336,
     'ext': 'mp4', 'format': '134 - 640x360 (DASH video)', 'height': 360, 'acodec': 'none'},
    {'format_note': 'DASH video', 'url': 'https://r2---sn-3u-bh2k.googlevideo.com/videoplayback?id=2b917e6860c861a3&itag=244&source=youtube&requiressl=yes&pl=17&mv=m&ms=au&mm=31&ratebypass=yes&mime=video/webm&gir=yes&clen=14372481&lmt=1415693046776509&dur=437.667&signature=8791E3F4CB49AD81E3BF87432B1ADA6E5F3CB3DA.32F372AD48DB55E8139E27995A79B10864D41FF4&sver=3&mt=1421408115&upn=AaiD5abqB5I&fexp=900718,905653,907263,916644,927622,931366,940000,9405888,941004,943917,947209,947225,948124,948813,952302,952605,952901,955301,957103,957105,957201,959701&key=dg_yt0&ip=222.112.46.51&ipbits=0&expire=1421429745&sparams=ip,ipbits,expire,id,itag,source,requiressl,pl,mv,ms,mm,ratebypass,mime,gir,clen,lmt,dur',
     'format_id': '244', 'asr': None, 'fps': 30, 'width': 854, 'preference': -40, 'filesize': 14372481, 'tbr': 665,
     'ext': 'webm', 'format': '244 - 854x480 (DASH video)', 'height': 480, 'acodec': 'none'},
    {'format_note': 'DASH video', 'url': 'https://r2---sn-3u-bh2k.googlevideo.com/videoplayback?id=2b917e6860c861a3&itag=135&source=youtube&requiressl=yes&pl=17&mv=m&ms=au&mm=31&ratebypass=yes&mime=video/mp4&gir=yes&clen=20652601&lmt=1416693194565587&dur=437.666&signature=6539381FD8276A4748B8AE247C60376EBDB1908B.4316D136D967F5DF6A4032A33C2F0E6CF03276DD&sver=3&mt=1421408115&upn=AaiD5abqB5I&fexp=900718,905653,907263,916644,927622,931366,940000,9405888,941004,943917,947209,947225,948124,948813,952302,952605,952901,955301,957103,957105,957201,959701&key=dg_yt0&ip=222.112.46.51&ipbits=0&expire=1421429745&sparams=ip,ipbits,expire,id,itag,source,requiressl,pl,mv,ms,mm,ratebypass,mime,gir,clen,lmt,dur',
     'format_id': '135', 'asr': None, 'fps': 30, 'width': 854, 'preference': -40, 'filesize': 20652601, 'tbr': 781,
     'ext': 'mp4', 'format': '135 - 854x480 (DASH video)', 'height': 480, 'acodec': 'none'},
    {'format_note': 'DASH video', 'url': 'https://r2---sn-3u-bh2k.googlevideo.com/videoplayback?id=2b917e6860c861a3&itag=247&source=youtube&requiressl=yes&pl=17&mv=m&ms=au&mm=31&ratebypass=yes&mime=video/webm&gir=yes&clen=33890382&lmt=1415693049756519&dur=437.667&signature=62A9FC35F6DF55840165F237B531B8F8F43FE7E8.31966089DFEBAE70C49089613BF835910914ED18&sver=3&mt=1421408115&upn=AaiD5abqB5I&fexp=900718,905653,907263,916644,927622,931366,940000,9405888,941004,943917,947209,947225,948124,948813,952302,952605,952901,955301,957103,957105,957201,959701&key=dg_yt0&ip=222.112.46.51&ipbits=0&expire=1421429745&sparams=ip,ipbits,expire,id,itag,source,requiressl,pl,mv,ms,mm,ratebypass,mime,gir,clen,lmt,dur',
     'format_id': '247', 'asr': None, 'fps': 30, 'width': 1280, 'preference': -40, 'filesize': 33890382, 'tbr': 1342,
     'ext': 'webm', 'format': '247 - 1280x720 (DASH video)', 'height': 720, 'acodec': 'none'},
    {'format_note': 'DASH video', 'url': 'https://r2---sn-3u-bh2k.googlevideo.com/videoplayback?id=2b917e6860c861a3&itag=136&source=youtube&requiressl=yes&pl=17&mv=m&ms=au&mm=31&ratebypass=yes&mime=video/mp4&gir=yes&clen=45605559&lmt=1416693176456443&dur=437.666&signature=096BE0C5710C32846F10E41C036322E60FE7AD4E.456183E8173383C782AEE30764D7EA966E75FA92&sver=3&mt=1421408115&upn=AaiD5abqB5I&fexp=900718,905653,907263,916644,927622,931366,940000,9405888,941004,943917,947209,947225,948124,948813,952302,952605,952901,955301,957103,957105,957201,959701&key=dg_yt0&ip=222.112.46.51&ipbits=0&expire=1421429745&sparams=ip,ipbits,expire,id,itag,source,requiressl,pl,mv,ms,mm,ratebypass,mime,gir,clen,lmt,dur',
     'format_id': '136', 'asr': None, 'fps': 30, 'width': 1280, 'preference': -40, 'filesize': 45605559, 'tbr': 1885,
     'ext': 'mp4', 'format': '136 - 1280x720 (DASH video)', 'height': 720, 'acodec': 'none'},
    {'url': 'https://r2---sn-3u-bh2k.googlevideo.com/videoplayback?itag=17&signature=0532F67D69950660BE7311F81A0F04B3E4320694.818D617928959C7417090535920156260C3D8D17&sver=3&requiressl=yes&expire=1421429745&pl=17&mv=m&sparams=dur%2Cid%2Cinitcwndbps%2Cip%2Cipbits%2Citag%2Cmime%2Cmm%2Cms%2Cmv%2Cpl%2Crequiressl%2Csource%2Cupn%2Cexpire&mt=1421408115&ms=au&id=o-AAIeqH7Ntb6VHo7-pkn8gjKUYEiqv7nPPKT2r7rUlahn&mm=31&source=youtube&upn=AaiD5abqB5I&dur=437.928&fexp=900718%2C905653%2C907263%2C916644%2C927622%2C931366%2C940000%2C9405888%2C941004%2C943917%2C947209%2C947225%2C948124%2C948813%2C952302%2C952605%2C952901%2C955301%2C957103%2C957105%2C957201%2C959701&initcwndbps=2827500&mime=video%2F3gpp&ip=222.112.46.51&key=yt5&ipbits=0&ratebypass=yes',
     'format_id': '17', 'player_url': None, 'format': '17 - 176x144', 'ext': '3gp', 'width': 176, 'height': 144},
    {'url': 'https://r2---sn-3u-bh2k.googlevideo.com/videoplayback?itag=36&signature=98083E2EAE9DD91FE0A1BCC773D5F20A142B2A53.9BFAAEBEDB23A62CFB2BE8796EDE4103CDF14541&sver=3&requiressl=yes&expire=1421429745&pl=17&mv=m&sparams=dur%2Cid%2Cinitcwndbps%2Cip%2Cipbits%2Citag%2Cmime%2Cmm%2Cms%2Cmv%2Cpl%2Crequiressl%2Csource%2Cupn%2Cexpire&mt=1421408115&ms=au&id=o-AAIeqH7Ntb6VHo7-pkn8gjKUYEiqv7nPPKT2r7rUlahn&mm=31&source=youtube&upn=AaiD5abqB5I&dur=437.881&fexp=900718%2C905653%2C907263%2C916644%2C927622%2C931366%2C940000%2C9405888%2C941004%2C943917%2C947209%2C947225%2C948124%2C948813%2C952302%2C952605%2C952901%2C955301%2C957103%2C957105%2C957201%2C959701&initcwndbps=2827500&mime=video%2F3gpp&ip=222.112.46.51&key=yt5&ipbits=0&ratebypass=yes',
     'format_id': '36', 'player_url': None, 'format': '36 - 320x240', 'ext': '3gp', 'width': 320, 'height': 240},
    {'url': 'https://r2---sn-3u-bh2k.googlevideo.com/videoplayback?itag=5&signature=AC4067EB8F9351D6F44AF2EF0DD55EABB7F713F5.40BB2A68A5916C827B42B65123D27896E2098A72&sver=3&requiressl=yes&expire=1421429745&pl=17&mv=m&sparams=dur%2Cid%2Cinitcwndbps%2Cip%2Cipbits%2Citag%2Cmime%2Cmm%2Cms%2Cmv%2Cpl%2Crequiressl%2Csource%2Cupn%2Cexpire&mt=1421408115&ms=au&id=o-AAIeqH7Ntb6VHo7-pkn8gjKUYEiqv7nPPKT2r7rUlahn&mm=31&source=youtube&upn=AaiD5abqB5I&dur=437.786&fexp=900718%2C905653%2C907263%2C916644%2C927622%2C931366%2C940000%2C9405888%2C941004%2C943917%2C947209%2C947225%2C948124%2C948813%2C952302%2C952605%2C952901%2C955301%2C957103%2C957105%2C957201%2C959701&initcwndbps=2827500&mime=video%2Fx-flv&ip=222.112.46.51&key=yt5&ipbits=0&ratebypass=yes',
     'format_id': '5', 'player_url': None, 'format': '5 - 400x240', 'ext': 'flv', 'width': 400, 'height': 240},
    {'url': 'https://r2---sn-3u-bh2k.googlevideo.com/videoplayback?requiressl=yes&sparams=dur%2Cid%2Cinitcwndbps%2Cip%2Cipbits%2Citag%2Cmime%2Cmm%2Cms%2Cmv%2Cpl%2Cratebypass%2Crequiressl%2Csource%2Cupn%2Cexpire&initcwndbps=2827500&key=yt5&expire=1421429745&signature=A9D6EC1E1C99AD6D8AD87B884ED8C49E08AA173D.BEE4473584053FAA5C0F94AB1792418B7D429783&sver=3&fexp=900718%2C905653%2C907263%2C916644%2C927622%2C931366%2C940000%2C9405888%2C941004%2C943917%2C947209%2C947225%2C948124%2C948813%2C952302%2C952605%2C952901%2C955301%2C957103%2C957105%2C957201%2C959701&ipbits=0&itag=43&upn=AaiD5abqB5I&dur=0.000&mime=video%2Fwebm&pl=17&mv=m&mt=1421408115&ms=au&id=o-AAIeqH7Ntb6VHo7-pkn8gjKUYEiqv7nPPKT2r7rUlahn&mm=31&source=youtube&ip=222.112.46.51&ratebypass=yes',
     'format_id': '43', 'player_url': None, 'format': '43 - 640x360', 'ext': 'webm', 'width': 640, 'height': 360},
    {'url': 'https://r2---sn-3u-bh2k.googlevideo.com/videoplayback?requiressl=yes&sparams=dur%2Cid%2Cinitcwndbps%2Cip%2Cipbits%2Citag%2Cmime%2Cmm%2Cms%2Cmv%2Cpl%2Cratebypass%2Crequiressl%2Csource%2Cupn%2Cexpire&initcwndbps=2827500&key=yt5&expire=1421429745&signature=12ECEB20A7EF802D831DB1DD35A235CBC2B54FF6.4E370E89FA2B84F113A71DE2D5255FE1223F42D8&sver=3&fexp=900718%2C905653%2C907263%2C916644%2C927622%2C931366%2C940000%2C9405888%2C941004%2C943917%2C947209%2C947225%2C948124%2C948813%2C952302%2C952605%2C952901%2C955301%2C957103%2C957105%2C957201%2C959701&ipbits=0&itag=18&upn=AaiD5abqB5I&dur=437.789&mime=video%2Fmp4&pl=17&mv=m&mt=1421408115&ms=au&id=o-AAIeqH7Ntb6VHo7-pkn8gjKUYEiqv7nPPKT2r7rUlahn&mm=31&source=youtube&ip=222.112.46.51&ratebypass=yes',
     'format_id': '18', 'player_url': None, 'format': '18 - 640x360', 'ext': 'mp4', 'width': 640, 'height': 360},
    {'url': 'https://r2---sn-3u-bh2k.googlevideo.com/videoplayback?requiressl=yes&sparams=dur%2Cid%2Cinitcwndbps%2Cip%2Cipbits%2Citag%2Cmime%2Cmm%2Cms%2Cmv%2Cpl%2Cratebypass%2Crequiressl%2Csource%2Cupn%2Cexpire&initcwndbps=2827500&key=yt5&expire=1421429745&signature=7BE8DC33A5728F6DF6CAC221B777D7D859D0B415.2A989D80263320ADF089EE1FC8274FFF3EA74130&sver=3&fexp=900718%2C905653%2C907263%2C916644%2C927622%2C931366%2C940000%2C9405888%2C941004%2C943917%2C947209%2C947225%2C948124%2C948813%2C952302%2C952605%2C952901%2C955301%2C957103%2C957105%2C957201%2C959701&ipbits=0&itag=22&upn=AaiD5abqB5I&dur=437.789&mime=video%2Fmp4&pl=17&mv=m&mt=1421408115&ms=au&id=o-AAIeqH7Ntb6VHo7-pkn8gjKUYEiqv7nPPKT2r7rUlahn&mm=31&source=youtube&ip=222.112.46.51&ratebypass=yes',
     'format_id': '22', 'player_url': None, 'format': '22 - 1280x720', 'ext': 'mp4', 'width': 1280, 'height': 720}],
'uploader': 'thenewboston', 'webpage_url': 'https://www.youtube.com/watch?v=K5F-aGDIYaM',
'playlist_index': None, 'format_id': '140', 'uploader_id': 'thenewboston', 'extractor_key': 'Youtube',
'preference': -50, 'width': None, 'filesize': 7028854, 'thumbnail': 'https://i.ytimg.com/vi/K5F-aGDIYaM/maxresdefault.jpg',
'playlist': None, 'annotations': None, 'asr': 44100, 'age_limit': 0, 'dislike_count': 4, 'view_count': 17206,
'url': 'https://r2---sn-3u-bh2k.googlevideo.com/videoplayback?id=2b917e6860c861a3&itag=140&source=youtube&requiressl=yes&pl=17&mv=m&ms=au&mm=31&ratebypass=yes&mime=audio/mp4&gir=yes&clen=7028854&lmt=1416693191330273&dur=437.788&signature=993247ED96F548F401B69C6BC93D510629D61816.15299F6D5512337484397B492C5409CD43CED949&sver=3&mt=1421408115&upn=AaiD5abqB5I&fexp=900718,905653,907263,916644,927622,931366,940000,9405888,941004,943917,947209,947225,948124,948813,952302,952605,952901,955301,957103,957105,957201,959701&key=dg_yt0&ip=222.112.46.51&ipbits=0&expire=1421429745&sparams=ip,ipbits,expire,id,itag,source,requiressl,pl,mv,ms,mm,ratebypass,mime,gir,clen,lmt,dur',
'description': 'Visit my website at https://www.thenewboston.com/ for all of my videos and tutorials!\nHave questions or looking for source code? Check out the forum at https://www.thenewboston.com/forum/\n\nsentdex YouTube Channel - https://www.youtube.com/user/sentdex\nMy Profile - https://www.thenewboston.com/profile.php?user=2\nFacebook - http://www.facebook.com/pages/TheNewBoston/464114846956315\nGoogle+ - https://plus.google.com/+BuckyRoberts/posts\nTwitter - http://twitter.com/#!/bucky_roberts\nDonate - https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=5K9RJVCAKWZKS',
'id': 'K5F-aGDIYaM', 'vcodec': 'none', 'duration': 438, 'fps': None, 'like_count': 199, 'webpage_url_basename': 'watch',
'upload_date': '20141110', 'display_id': 'K5F-aGDIYaM', 'height': None, 'extractor': 'youtube', 'tbr': 129,
'subtitles': None, 'abr': 128, 'ext': 'm4a', 'title': 'Pygame (Python Game Development) Tutorial - 1 - Introduction',
'categories': ['Education'], 'format': '140 - audio only (DASH audio)', 'acodec': 'aac'}
m4a nondash-140   nondash-140 - audio only (DASH audio)
mp4 nondash-160  144 nondash-160 - 144p (DASH video)
mp4 nondash-133  240 nondash-133 - 240p (DASH video)
mp4 nondash-134  360 nondash-134 - 360p (DASH video)
mp4 nondash-135  480 nondash-135 - 480p (DASH video)
mp4 nondash-136  720 nondash-136 - 720p (DASH video)
m4a 139 None None 139 - audio only (DASH audio)
m4a 140 None None 140 - audio only (DASH audio)
m4a 141 None None 141 - audio only (DASH audio)
mp4 160 256 144 160 - 256x144 (DASH video)
mp4 133 426 240 133 - 426x240 (DASH video)
mp4 134 640 360 134 - 640x360 (DASH video)
mp4 135 854 480 135 - 854x480 (DASH video)
mp4 136 1280 720 136 - 1280x720 (DASH video)
3gp 17 176 144 17 - 176x144
3gp 36 320 240 36 - 320x240
flv 5 400 240 5 - 400x240
webm 43 640 360 43 - 640x360
mp4 18 640 360 18 - 640x360
mp4 22 1280 720 22 - 1280x720

        '''
        with youtube_dl.YoutubeDL(ydl_opts) as ydl:
            tube_info = ydl.extract_info(
                self.sel_tube,
                download=False  # We just want to extract the info
            )
            print("=================================================================================")
            print(tube_info['title'])
            print("=================================================================================")
            all_formats = tube_info['formats']
            items = []
            for itm in all_formats:
                ext = itm['ext']
                fmt = itm['format']
                fid = itm['format_id']
                try: asr = itm['asr']
                except KeyError: asr = ''
                try: abr = itm['abr']
                except KeyError: abr = ''
                try: tbr = itm['tbr']
                except KeyError: tbr = ''
                try: width = itm['width']
                except KeyError: width = ''
                try: height = itm['height']
                except KeyError: height = ''
                itm = str("ext=%s, w=%s, h=%s, asr=%s, abr=%s, tbr=%s, id=%s, format=%s"
                          % (ext, width, height, asr, abr, tbr, fid, fmt))
                items.append(itm)
            items.sort()
            self.info_list.delete(0, tk.END)  # clear
            for itm in items:
                self.info_list.insert(tk.END, itm)

            # ydl.download(['http://www.youtube.com/watch?v=WnKUvfVE2R8',
            #               'http://www.youtube.com/watch?v=L8VE7o4wkM0'])

    def _on_down(self, event=None):
        pass

    def _on_double_click_play_list(self, event=None):
        widget = event.widget
        selection = widget.curselection()
        if len(selection) > 0:
            val = widget.get(selection[0])
            print(val)
            self._infourl.set(val)
            self.sel_tube = self.TUBE_URL + val
        self._on_get_info()

if __name__ == '__main__':
    print('getube 0.0.1')
    app = TubeApp()
    app.geometry("600x400+0+0")
    app.mainloop()
# -f 136/137/mp4/bestvideo,140/m4a/bestaudio